package cn.edu.cdu.farmdeal.controller;

import cn.edu.cdu.farmdeal.service.DetailService;
import cn.edu.cdu.farmdeal.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Author: tupeng
 * @Date: 2020/3/30
 **/
@Controller
public class DetailController {
    @Autowired
    private DetailService detailService;

    @RequestMapping("/detail.html")
    public ModelAndView getDetail(ModelAndView modelAndView,
                               HttpServletRequest request){
        HttpSession session1 = request.getSession();
//        session1.setAttribute("userid", "admin");
        modelAndView.setViewName("shopdetail");
        return modelAndView;
    }

    @GetMapping("/detail/getImage")
    @ResponseBody
    public R getImage(String id){
        return R.ok().put("data",detailService.getImage(Integer.parseInt(id)));
    }

    @GetMapping("/detail/getDetail")
    @ResponseBody
    public R getDetail(String id){
        return R.ok().put("data",detailService.getDetail(Integer.parseInt(id)));
    }

    @GetMapping("/detail/getShopHot")
    @ResponseBody
    public R getShopHot(String id){
        return R.ok().put("data",detailService.getShopHot(Integer.parseInt(id)));
    }

    @GetMapping("/detail/getSpec")
    @ResponseBody
    public R getSpec(String id){
        return R.ok().put("data",detailService.getSpec(Integer.parseInt(id)));
    }

    @GetMapping("/detail/checkPro")
    @ResponseBody
    public R checkPro(String id,String userName){
        return R.ok().put("data",detailService.checkPro(id, userName));
    }

    @PostMapping("/detail/commitCart")
    @ResponseBody
    public R commitCart(@RequestBody Map<String,Object> map){
        return R.ok().put("data",detailService.commitCart(map));
    }

    @PostMapping("/detail/saveTempPro")
    @ResponseBody
    public R saveTempPro(@RequestBody Map<String,Object> map){
        return R.ok().put("data",detailService.saveTempPro(map));
    }
}
